package com.baosight.sczx.common.zm.cInterface.cn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * <p>Title: CustomInfo.java</p>
 * <p>Description: 选择客户</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author lhx
 * @version 1.0
 * <pre>Histroy:
 *          2016-10-15 18:08:51  李红星  Create
 *</pre>
 */
public class CustomInfo {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	private static CustomInfo instance=new CustomInfo();
	
	@SuppressWarnings("rawtypes")
	private static List<Map> _list;
	
	private CustomInfo(){
		initData();
	}
	
	/**
	 * 初始化数据
	 * <p>Function: initData</p>
	 * <p>Description: </p>
	 * <p>return value:void</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-9-19 10:59:31 李红星 create
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void initData() {
		if(_list != null) {
			_list = null;
		}
		_list = new ArrayList<Map>();
		try {
			_list = dao.query("ZMCNCustomInfo.query_interface", null);
		} catch (Exception e) {
			System.out.println(CustomInfo.class.getName() + "获取煤质销售客户信息异常：" + e.getMessage());
		}
	}
	
	/**
	 * 选择煤质销售或外购客户信息
	 * 
	 * @param blockId String 要构造的block的id
	 * @param status String 记录状态 为空表示草拟和生效的数据
	 * @param type Sring 外购、销售
	 * @return EiBlock
	 * 
	 * @author hongxing
	 * @since 2016-9-19 16:58:13
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiBlock getCustomBlock(String blockId,String _display,String _value,String status,String type) {
		EiBlock block = new EiBlock(blockId);

		EiColumn EiColumn = new EiColumn(_value);
		EiColumn.setType("C");
		block.addMeta(EiColumn);
		
		EiColumn = new EiColumn(_display);
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		_map.put(_display, "");
		_map.put(_value, "");
		list.add(_map);
        
		for(int i = 0; i < _list.size(); i++) {
			Map<String,String> tmpMap=new HashMap<String,String>();
			_map = _list.get(i);
			if(status==null || status.equals("")){
                if(_map.get("fdType").equals(type)){
					tmpMap.put(_value, _map.get(_value));
					tmpMap.put(_display, _map.get(_display));
					list.add(tmpMap); 
                }
			}else if(status!=null && !status.equals("")){
				if(_map.get("fdStatus").equals(status) && _map.get("fdType").equals(type)){
					tmpMap.put(_value, _map.get(_value));
					tmpMap.put(_display, _map.get(_display));
					list.add(tmpMap); 
				}
			}
		} 
		block.setRows(list);
		return block;
	}
	
	/**
	 * 初始化该类
	 * <p>Function: getInstance</p>
	 * <p>Description:初始化煤样编码类 </p>
	 * <p>return value:InitialData</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-9-19 17:10:52 李红星
	 * </p>
	 *
	 */
	public static CustomInfo getInstance(){
		instance=new CustomInfo();
		return instance;
	}
}
